package gazzera.swing.browse;

import gazzera.utils.*;

import java.util.*;

import javax.swing.table.*;


public class FileTableModel extends AbstractTableModel
{

    List<RemoteFile> files = new ArrayList<RemoteFile>();
    private ByteFormatter bf = new ByteFormatter();
    
    @Override
    public int getColumnCount()
    {
	return 3;
    }

    @Override
    public int getRowCount()
    {
	return files.size();
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex)
    {
	RemoteFile f = files.get(rowIndex);
	switch (columnIndex)
	{
	case 0:
	    return f;
	case 1:
	    return f.name;
	case 2:
	    return bf.formatByteSize( f.size );
	}
	
	return null;
    }

    public void add(RemoteFile r)
    {
	files.add(r);
	fireTableRowsInserted(files.size()-1, files.size()-1);
    }
    
}
